package cc.rboot.inject.template;

import cc.rboot.inject.core.AbstractMapperInjector;
import javassist.NotFoundException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

@RestController
@RequestMapping(path = "/_inject")
public class InjectGet<T> extends AbstractMapperInjector<T> {

    /**
     * 默认的查询指定资源接口
     *
     * @param id
     */
    @GetMapping(path = "/{id}")
    public T _execute(@PathVariable(value = "id", required = true) Serializable id) throws Exception {
        T entity = super.getService().getById(id);
        if (null == entity) {
            throw new NotFoundException("找不到资源");
        }
        return entity;
    }
}
